home *** CD-ROM | disk | FTP | other *** search
- Path: prodigy.com!usenet
- From: XKWR65B@prodigy.com (Mark Rubelmann)
- Newsgroups: comp.lang.c++
- Subject: HELP! .PCXes and Null Pointer error...
- Date: 6 Apr 1996 21:36:10 GMT
- Organization: Prodigy Services Company 1-800-PRODIGY
- Distribution: world
- Message-ID: <4k6o4a$1m5a@usenetp1.news.prodigy.com>
- NNTP-Posting-Host: innugap8-int.news.prodigy.com
- X-Newsreader: Version 1.2
-
- I'm having trouble with this function to load PCX files. It compiles fine
- but crashes when I try to run it. One time as I was messing around with
- it, it sort of worked. All it did was show a bunch of crap on the screen
- when it tried to draw it and when the program was done running it said
- "Null pointer assignment." Here's the data structure for the PCX file and
- two functions to allocate the memory and load it:
-
- typedef struct pcx_picture_typ
- {
- pcx_header header; // 128 byte header
- RGB_color palette[256]; // The palette
- char far *buffer; // Decompressed image
- } pcx_picture, *pcx_picture_ptr;
-
-
- int PCX_Init(pcx_picture_ptr image)
- {
- if(!(image->buffer = (char far *)malloc(64001)))
- return 0;
- else
- return 1;
- }
-
- void PCX_Load(char *filename, pcx_picture_ptr image)
- {
- FILE *fp;
- int num_bytes,index;
- long count=0;
- unsigned char data;
- char far *temp_buffer;
-
- fp = fopen(filename, "rb"); // Open the file
-
- temp_buffer = (char far *)image; //Load header
- for(index=0; index<128; index++)
- temp_buffer[index] = getc(fp);
-
- while(count<=ScrWidth * ScrHeight) // Load data and decompress it
- {
- data = getc(fp); // Get first piece of data
- if(data>=192 && data>=255) // Is it RLE?
- {
- num_bytes=data-192; // How many bytes in run?
- data = getc(fp); // Get data for run
- while(num_bytes-->0) // Replicate data in buffer num_bytes
- times
- {
- image->buffer[count++] = data;
- }
- }
- else
- {
- image->buffer[count++] = data; // Just copy data into buffer
- }
- }
-
- fseek(fp,-768L,SEEK_END); // Go to the start of the palette data
- for(index=0;index<256;index++) // Load the palette
- {
- image->palette[index].red = (getc(fp) >> 2); // Get red value
- image->palette[index].green = (getc(fp) >> 2); // Get green
- image->palette[index].blue = (getc(fp) >> 2); // Get blue
- }
-
- fclose(fp); // Close the file
- }
-
- I believe the problem is that the data just isn't getting stored in image.
- buffer like it's supposed to. Please help!
-
-